import {take,put,call,fork} from 'redux-saga/effects';
import getSerLoginData from '../servers/serLogin';
//登录
function *sagLogin() {
    while (true){
        let action=yield take('ACTLOGIN');
        let payload =yield call(getSerLoginData,action.data);
        let temPayLoad = payload;
        let redLoginData={};
        if(temPayLoad.code===200){
            redLoginData.uid=temPayLoad.data.uid;
            redLoginData.username=temPayLoad.data.nickname;
            redLoginData.authtoken=temPayLoad.data.auth_token;
            redLoginData.isLogin=action.data.isLogin;
            yield put({type:'redLogin',data:redLoginData});
            action.data.GoPagePush(action.data.props,'home/user');

        }else {
            action.data.Toast.info(temPayLoad.data,2)
        };
    }
}
//退出
function * sagOutLogin() {
    while (true){
        let action=yield take('actOutLogin');
        let redLoginData={};
        redLoginData.uid=action.data.uid;
        redLoginData.username=action.data.nickname;
        redLoginData.authtoken=action.data.authtoken;
        redLoginData.isLogin=action.data.isLogin;
       yield put({type:'redOutLogin',data:redLoginData});
       if(action.data.success){
           action.data.success()
       }
    }
}
export default [
    fork(sagLogin),
    fork(sagOutLogin)
]